package com.qf.xiaomi.web.servlet;

import com.qf.xiaomi.service.impl.UserServiceImpl;
import com.qf.xiaomi.utils.Base64Utils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Created by 马英超 on 2022/8/16 22:11
 * @author： 马英超
 * @version：v1.0
 * @description:
 */
@WebServlet("/activate")
public class ActivateServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        final String e = req.getParameter("e");
        final String c = req.getParameter("c");

        //解码
        final String email = Base64Utils.decode(e);
        final String code = Base64Utils.decode(c);
        System.out.println("email\t"+email);
        System.out.println("code\t"+code);

        //嗲用Service
        UserServiceImpl userService=new UserServiceImpl();
       boolean activeResult= userService.activeUser(email,code);
       if (activeResult==true){
            resp.sendRedirect("/ActiveSuccess.jsp");
       }

    }
}
